package com.molyfun.parents.activity.common.listactivity.factory;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.molyfun.parents.MFPApplication;
import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.listactivity.AbstractListFactory;
import com.molyfun.parents.activity.common.listactivity.IResponse;
import com.molyfun.parents.activity.common.listactivity.viewholder.ReportResultViewHolder;
import com.molyfun.parents.activity.report.ReportResultActivity;
import com.molyfun.parents.rest.RestClient;
import com.molyfun.parents.rest.bean.ReportResultResponse;
import com.molyfun.parents.view.HorizontalTagBar;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by william(liuchao.hit@gmail.com).
 * 我的界面-评估
 */
public class EvaluateFactory extends AbstractListFactory<ReportResultResponse.EvaluateListBean> {

    public EvaluateFactory(){

    }

    @Override
    public int getTitle() {
        return R.string.activity_title_mine_evaluate;
    }

    @Override
    public void getDataList(int pageNum,final IResponse responseCallback) {


        Call<ReportResultResponse> call = MFPApplication.getInstance().getRestClient().getEvaluateList(pageNum, RestClient.DEFAULT_PAGE_SIZE);
        call.enqueue(new Callback<ReportResultResponse>() {
            @Override
            public void onResponse(Call<ReportResultResponse> call, Response<ReportResultResponse> response) {
                if (response.body() != null && response.body().getData() != null && response.body().getData().getRecords() != null) {
                    responseCallback.onResponse(response.body().getData().getRecords());

                }
            }

            @Override
            public void onFailure(Call<ReportResultResponse> call, Throwable t) {
            }
        });

    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int viewType) {
        return new ReportResultViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_report_result_list_cell, parent, false));
    }

    @Override
    public void bindViewHolder(final Context context, final ReportResultResponse.EvaluateListBean evaluateListBean, RecyclerView.ViewHolder holder, final int position, FragmentManager fragmentManager, int totalSize) {

        ReportResultViewHolder reportResultViewHolder = (ReportResultViewHolder)holder;
        reportResultViewHolder.mTimeInterval.setText(evaluateListBean.getDatestr());
        if(evaluateListBean.getEvaluatelist() == null || evaluateListBean.getEvaluatelist().size() == 0){
            reportResultViewHolder.mResultType.setVisibility(View.GONE);
        }else{
            reportResultViewHolder.mResultType.setVisibility(View.VISIBLE);
            reportResultViewHolder.mResultType.initDataList(evaluateListBean.getEvaluatelist());
        }
        reportResultViewHolder.mResultType.setOnHorizontalTagBarClickListener(new HorizontalTagBar.OnHorizontalTagBarClickListener() {
            @Override
            public void onTagBarClick(int position) {
                ReportResultActivity.startActivity(context , evaluateListBean.getEvaluatelist().get(position).getId(),"");
            }
        });
    }

    @Override
    public void deleteData(final String id,final int position) {
    }
}
